IF(BUILD_PYTHON_INTERFACE)
  ADD_SUBDIRECTORY(bindings)
ENDIF(BUILD_PYTHON_INTERFACE)

ADD_SUBDIRECTORY(python)


FILE(GLOB_RECURSE ${PROJECT_NAME}_FACTORY_TEST
  ${CMAKE_CURRENT_SOURCE_DIR}/factory/*.cpp
  )

IF(UNIX)
  ADD_LIBRARY(${PROJECT_NAME}_unittest SHARED ${${PROJECT_NAME}_FACTORY_TEST})
  SET_TARGET_PROPERTIES(${PROJECT_NAME}_unittest PROPERTIES LINKER_LANGUAGE CXX)
  TARGET_LINK_LIBRARIES(${PROJECT_NAME}_unittest ${PROJECT_NAME} example-robot-data::example-robot-data)

  if(OPENMP_FOUND)
    TARGET_LINK_LIBRARIES(${PROJECT_NAME}_unittest ${OpenMP_CXX_LIBRARIES})
  ENDIF()
ENDIF(UNIX)


SET(${PROJECT_NAME}_CPP_TESTS
  test_states
  test_actuation
  test_activations
  test_costs
  test_cost_sum
  test_contacts
  test_impulses
  test_multiple_contacts
  test_multiple_impulses
  test_actions
  # test_integrators
  test_diff_actions
  test_friction_cone
  test_boxqp
  test_solvers
)

IF(BUILD_WITH_CODEGEN_SUPPORT)
  SET(${PROJECT_NAME}_CODEGEN_CPP_TESTS
    test_codegen
    )
  LIST(APPEND ${PROJECT_NAME}_CPP_TESTS ${${PROJECT_NAME}_CODEGEN_CPP_TESTS})
ENDIF()


INCLUDE_DIRECTORIES(.)

MACRO(ADD_TEST_CFLAGS target flag)
  SET_PROPERTY(TARGET ${target} APPEND_STRING PROPERTY COMPILE_FLAGS " ${flag}")
ENDMACRO(ADD_TEST_CFLAGS)

FOREACH(NAME ${${PROJECT_NAME}_CPP_TESTS})
  SET(UNITTEST_NAME ${NAME})

  ADD_UNIT_TEST(${UNITTEST_NAME} ${NAME}.cpp)
  SET_TESTS_PROPERTIES(${UNITTEST_NAME} PROPERTIES TIMEOUT 7200)

  SET_TARGET_PROPERTIES(${UNITTEST_NAME} PROPERTIES LINKER_LANGUAGE CXX)

  ADD_TEST_CFLAGS(${UNITTEST_NAME} "-DBOOST_TEST_DYN_LINK")

  SET(MODULE_NAME "${NAME}Test")
  STRING(REGEX REPLACE "-" "_" MODULE_NAME ${MODULE_NAME})
  ADD_TEST_CFLAGS(${UNITTEST_NAME} "-DTEST_MODULE_NAME=${MODULE_NAME}")
  ADD_TEST_CFLAGS(${UNITTEST_NAME} "-DBOOST_TEST_MODULE=${MODULE_NAME}")

  TARGET_LINK_LIBRARIES(${UNITTEST_NAME} ${PROJECT_NAME} ${PROJECT_NAME}_unittest)
  TARGET_LINK_LIBRARIES(${UNITTEST_NAME} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
  TARGET_LINK_LIBRARIES(${UNITTEST_NAME} example-robot-data::example-robot-data)

  ADD_TEST_CFLAGS(${UNITTEST_NAME} '-DCROCODDYL_SOURCE_DIR=\\\"${${PROJECT_NAME}_SOURCE_DIR}\\\"')
ENDFOREACH(NAME ${${PROJECT_NAME}_CPP_TESTS})

IF(BUILD_WITH_CODEGEN_SUPPORT)
  FOREACH(TEST_NAME ${${PROJECT_NAME}_CODEGEN_CPP_TESTS})
    TARGET_LINK_LIBRARIES(${TEST_NAME} ${CMAKE_DL_LIBS})
  ENDFOREACH(BENCHMARK_NAME ${${PROJECT_NAME}_CODEGEN_CPP_TESTS})
ENDIF()

